export default {
  data() {
    // 设置校验规则(可自定义)
    var rules = {}
    this.validateItems.forEach(item => {
      var validateFun = (rules, value, callback) => {
        let validateSuccessFlag = true
        const { dataType } = item
        if ((dataType === 'array' && value.length === 0) || value === '') {
          validateSuccessFlag = false
        }
        if (!validateSuccessFlag) {
          if (item.type === 'select') {
            return callback(new Error(`尚未选择${item.label}`))
          } else {
            return callback(new Error(`${item.label}不能为空`))
          }
        } else {
          callback()
        }
      }
      rules[item.key] = [
        {
          required: true,
          validator: typeof (item.validate) === 'function' ? item.validate : validateFun,
          trigger: item.trigger ? item.trigger : 'blur'
        }
      ]
    })
    console.log(rules, 'ruless')
    return {
      rules: rules
    }
  },
  methods: {
    async runFun() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          this.submitEdit()
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
